Skip to content

fix: apply showMemberMiddleware to flowsheet write routes#187

Open
jakebromberg wants to merge 4 commits intomainfrom
fix/10-apply-show-member-middleware
Open

fix: apply showMemberMiddleware to flowsheet write routes#187
jakebromberg wants to merge 4 commits intomainfrom
fix/10-apply-show-member-middleware

Conversation

@jakebromberg
Copy link
Member

Summary

  • Bug: showMemberMiddleware was imported in apps/backend/app.ts but never applied to any route, allowing any authenticated DJ to modify flowsheet entries even without joining the active show.
  • Fix: Applied showMemberMiddleware after requirePermissions on the POST, PATCH, and DELETE flowsheet routes in flowsheet.route.ts. Removed the unused import from app.ts.
  • Hardening: Added try/catch error handling to the middleware (previously had none) and simplified the DJ lookup from .filter().length to .some().

Test plan

  • Unit tests for showMemberMiddleware covering:
    • DJ not in show → returns 400
    • DJ in show → calls next()
    • No DJs in show → returns 400
    • DB error → returns 500 (new error handling)
  • Full unit test suite passes (124 tests, 9 suites)

Fixes #10

Made with Cursor

The middleware was imported but never applied, allowing any authenticated
DJ to modify flowsheet entries regardless of show membership.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jakebromberg jakebromberg force-pushed the fix/10-apply-show-member-middleware branch from 0f349db to f392fe2 Compare February 27, 2026 05:56
Jake Bromberg added 3 commits February 27, 2026 14:03
The showMemberMiddleware checks req.auth for the user ID, but when
AUTH_BYPASS=true the requirePermissions middleware skips JWT verification
and never sets req.auth. This caused all flowsheet write routes to
return 400 in integration tests. Follow the same AUTH_BYPASS pattern
used by requirePermissions.
Use beforeEach to clear AUTH_BYPASS before each test and afterAll to
restore it once after the suite. The previous afterEach approach
restored AUTH_BYPASS to 'true' between tests in CI, causing later
tests to hit the bypass path instead of exercising the middleware.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants